package aperturescience.types;

import org.json.JSONException;
import org.json.JSONObject;
import org.restlet.ext.json.JsonRepresentation;

public class JSONMessageResponse {
	public static final String STATUS = "status_code";
	public static final String MESSAGE = "message";
	private static JSONObject message;
	
	static {
		message = new JSONObject();
	}
	/**
	 * @method generateMessage
	 * Generates a JSON Object of an message response
	 *
	 * @param statusCode	the status code of the request
	 * @param details		the message to-be-returned to user
	 * @pre  both are initialized
	 * @returns a JSON object of message
	 */
	public static JSONObject generateMessage(String statusCode, String details) {
		try {
			message.remove(STATUS);
			message.put(STATUS, statusCode);
			message.remove(MESSAGE);
			message.put(MESSAGE, details);
		} catch(JSONException e) { } 
		return message;
	}
	
	public static JsonRepresentation generateMessageRep(String statusCode, String details) {
		message = generateMessage(statusCode, details);
		return new JsonRepresentation(message);
	}
	
	public static JsonRepresentation generateMessageRep(int statusCode, String details) {
		message = generateMessage(""+statusCode, details);
		return new JsonRepresentation(message);
	}

}
